﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreValidationCode;
using TarreOA.TarreOAModels;

public partial class admin_DiscussAreaSetting_DiscussAreaEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString.Get("da_id") != null)
            {
                int da_id = int.Parse(Request.QueryString.Get("da_id"));
                DiscussAreaService daService = new DiscussAreaService();
                DiscussArea da = daService.findById(da_id);
                if (da != null)
                {
                    this.TxtAreaName.Text = da.DiscussAreaTitle;
                    this.IbtCreate.Attributes.Add("da_id", da.DiscussAreaId.ToString());
                }
            }
        }
    }
    protected void IbtCreate_Click(object sender, EventArgs e)
    {
        if (!Request.Form.Get(this.TxtValidatorCode.ClientID).Equals(Code.Codes))
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('验证码输入错误！');", true);
        }
        else
        {
            if (!"".Equals(Request.Form.Get(this.TxtAreaName.ClientID)) && Request.Form.Get(TxtAreaName.ClientID) != null)
            {
                DiscussAreaService daService = new DiscussAreaService();
                int da_id = int.Parse(((Button)sender).Attributes["da_id"]);
                string title = Request.Form.Get(this.TxtAreaName.ClientID);
                if (daService.UpdateDiscussAreaInfo(title, DateTime.Now, da_id) == 1)
                {
                    Response.Redirect("DiscussAreaIndex.aspx");
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('更新失败，请重试！');", true);
                }
            }
        }
    }
    protected void ImageButton3_Click(object sender, EventArgs e)
    {
        Response.Redirect("DiscussAreaIndex.aspx");
    }
}
